// pages/workList/workList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wordlist:[],
    index:0,
    // title:"题目",
    finishdat:"2021-02-09 16:07",
    whichtype:null,
    description:"描述",
    grade:null,
    typeListen:"听写",
    typeRecite:"背诵",
    phone:"",
    nolist:false
  },
 
  delete(e){
    var phoneNumber=wx.getStorageSync('phone');
    var item=e.currentTarget.dataset.id;;
    var id=this.data.wordlist[item].workId;
    var that=this;
    // 2022/11/5
    wx.showModal({
      title: '提示',
      content: "确认要删除吗？",
      success: function(res) {
      if(res.confirm){
        console.log('确定')
        wx.request({
          url: 'http://106.15.67.178:8080/delete?workId='+id,
          method:'DELETE',
            success:res=>{
              console.log(res.data.message);
              that.onShow();
            }
        })
      }else if(res.cancel){
        console.log('取消')
      }
    }
    })
  },
  
  toSearch() {
    wx.navigateTo({
      url: '/pages/search/search',
    })
   },
   
  toWork(e){
    var item=e.currentTarget.dataset.id;;
    // var Title='123';
    var Title=this.data.wordlist[item].tittle;
    var id=this.data.wordlist[item].workId;
    var descripte=this.data.wordlist[item].description;
    var content=this.data.wordlist[item].content;
    var type=this.data.wordlist[item].type;
    var status=this.data.wordlist[item].status;
    console.log(status)
    console.log('index:'+item)
      wx.navigateTo({
      url: '/pages/work/work?title='+Title+'&id='+id+'&description='+descripte+'&content='+content+'&status='+status,
    })
  },

  modify(e){
    var item=e.currentTarget.dataset.id;
    var Title=this.data.wordlist[item].tittle;
    var id=this.data.wordlist[item].id;
    // var type=this.data.wordlist[item].type;
    var descripte=this.data.wordlist[item].description;
    var content=this.data.wordlist[item].content;
    // console.log(type)
    console.log(this.data.wordlist[item].tittle)
    wx.navigateTo({
      url: '/pages/NewWorkImform/NewWorkImform?title='+Title+'&id='+id+'&description='+descripte+'&content='+content,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var getPhone = wx.getStorageSync('phone');
    if(getPhone){
      this.setData ({
        phone:getPhone
      })
      console.log("同步 从本地缓存取出数据phone=" +getPhone);
    }
    var that=this;
    var phoneNumber=wx.getStorageSync('phone');
    console.log(phoneNumber)
    wx.request({
      url: 'http://106.15.67.178:8080/getWorklist?ticket='+phoneNumber,
      // 18773392767
      method:'GET',
        success:res=>{
          console.log(res);
          var state=res.data.success;
          // if(!state){
          //   that.setData({
          //     nolist:true
          //   })
          // }
          if(false){
              that.setData({
              nolist:true
            })
          }
          else {
            //将获取到的作业列表存放到listarr中 ----2022/11/5
          // var listarr=res.data.data.list;
          var listarr=res.data;
          console.log(listarr);
          that.setData({
            wordlist:listarr,
            nolist:false
          })
          //  console.log(that.data.wordlist)
         }
        }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})